Repository navigation
Conversation
…time activation GDAL algorithms that embed python at runtime (e.g. gdal driver gpkg validate) import the osgeo_utils package, which was missing from the runtime bundle. Stage it from the GDAL source tree during the build (version-locked to the built tag), carry it into the bundle under python/, and prepend <gdal_home>/python to PYTHONPATH (session-scoped) in activate_gdal_runtime(). Add testthat coverage and an end-to-end gpkg validate smoke test in CI. Closes #7
feat: bundle pure-python osgeo_utils and expose via PYTHONPATH at run…
There was a problem hiding this comment.
Code Review
This pull request introduces support for GDAL's embedded Python algorithms by bundling the pure-python osgeo_utils package and prepending its path to PYTHONPATH during runtime activation. The changes include updates to the runtime activation logic, documentation, build and collection scripts, and comprehensive unit tests. The review feedback suggests improving path normalization on Windows to robustly check for existing PYTHONPATH entries, and cleaning up target directories in the build and collection scripts before copying files to prevent merging with stale files.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (dir.exists(python_dir)) { | ||
| py_parts <- strsplit(Sys.getenv("PYTHONPATH", unset = ""), path_sep, fixed = TRUE)[[1]] | ||
| py_parts <- py_parts[nzchar(py_parts)] | ||
| if (!python_dir %in% py_parts) { | ||
| Sys.setenv(PYTHONPATH = paste(c(python_dir, py_parts), collapse = path_sep)) | ||
| } | ||
| } |
There was a problem hiding this comment.
On Windows, path comparisons can fail due to differences in case sensitivity or slash direction (e.g., C:/path/to/python vs c:\\path\to\python). To ensure robust detection of existing PYTHONPATH entries and avoid duplicate or redundant additions, normalize both python_dir and py_parts (using tolower() and normalizePath()) before performing the %in% check.
if (dir.exists(python_dir)) {
py_parts <- strsplit(Sys.getenv("PYTHONPATH", unset = ""), path_sep, fixed = TRUE)[[1]]
py_parts <- py_parts[nzchar(py_parts)]
norm_python_dir <- tolower(normalizePath(python_dir, winslash = "/", mustWork = FALSE))
norm_py_parts <- tolower(normalizePath(py_parts, winslash = "/", mustWork = FALSE))
if (!norm_python_dir %in% norm_py_parts) {
Sys.setenv(PYTHONPATH = paste(c(python_dir, py_parts), collapse = path_sep))
}
}| mkdir -p "${INSTALL_DIR}/python" | ||
| cp -r "${SRC_DIR}/swig/python/gdal-utils/osgeo_utils" "${INSTALL_DIR}/python/" |
There was a problem hiding this comment.
If a previous build has already staged osgeo_utils in ${INSTALL_DIR}/python/osgeo_utils, running cp -r can merge new files with old/stale files from previous builds. To ensure a clean and reliable build, remove any existing osgeo_utils directory before copying.
| mkdir -p "${INSTALL_DIR}/python" | |
| cp -r "${SRC_DIR}/swig/python/gdal-utils/osgeo_utils" "${INSTALL_DIR}/python/" | |
| mkdir -p "${INSTALL_DIR}/python" | |
| rm -rf "${INSTALL_DIR}/python/osgeo_utils" | |
| cp -r "${SRC_DIR}/swig/python/gdal-utils/osgeo_utils" "${INSTALL_DIR}/python/" |
| mkdir -p "${BUNDLE_DIR}/python" | ||
| cp -r "${INSTALL_DIR}/python/." "${BUNDLE_DIR}/python/" |
There was a problem hiding this comment.
To prevent stale files from previous bundling attempts from persisting in the final bundle, it is safer to remove the existing ${BUNDLE_DIR}/python directory before recreating it and copying the new files.
| mkdir -p "${BUNDLE_DIR}/python" | |
| cp -r "${INSTALL_DIR}/python/." "${BUNDLE_DIR}/python/" | |
| rm -rf "${BUNDLE_DIR}/python" | |
| mkdir -p "${BUNDLE_DIR}/python" | |
| cp -r "${INSTALL_DIR}/python/." "${BUNDLE_DIR}/python/" |
See #8 & #7